package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(20);not null;comment:账号"`
	PassWord string `gorm:"type:char(32);comment:密码"`
	Nick     string `gorm:"type:varchar(20);comment:昵称"`
	RealName string `gorm:"type:varchar(20);comment:真实姓名"`
	IdCard   string `gorm:"type:char(18);comment:身份证号"`
	//身份证
	IdCardFrond string `gorm:"type:varchar(256);comment:身份证正面"`
	IdCardSide  string `gorm:"type:varchar(256);comment:身份证反面"`
	Status      int    `gorm:"type:tinyint(1);default:0;comment:状态(0-未审核,1-审核通过,2-审核未通过)"`
}

// 添加用户
func (u *User) Create() error {
	return DB.Create(&u).Error
}

// 查询用户
func (u *User) Find(account string) error {
	return DB.Where("account = ?", account).Find(&u).Error
}

// 修改用户权限
func (u *User) Update(userId, userStatus int) error {
	return DB.Model(&u).Where("user_id = ?", userId).Update("user_status", userStatus).Error
}

// 审核用户权限
func (u *User) First(id int) error {
	return DB.Where("id = ?", id).Updates(&u).Error
}

// 用户列表
func (u *User) FindUser(status int) (List []User) {
	if status != 0 {
		DB.Where("status = ?", status).Find(&List)
	}
	DB.Find(&List)
	return
}
